const userModel = require("../models/userModel");
//加密
const crypto = require('crypto');
const secret = 'abc'; //密钥
module.exports = {
    //查询用户
    async QueryUser(username, pwd) {
        return await userModel.findOne({
            name: username,
            password: crypto.createHmac('sha256', secret)
                .update(pwd) //密码
                .digest('hex')
        }).exec()
    },
    //注册用户
    async RegisteredUsers(username, pwd) {
        return await userModel.create({
            name: username,
            password: crypto.createHmac('sha256', secret)
                .update(pwd) //密码
                .digest('hex')
        })
    },
    async QueryName(username){
        return await userModel.findOne({name: username}).exec()
    }
}